import { getArtilceAll, getClassify, getKind} from "@/api/artilce/all.js";
// import {getHtml } from "@/api/artilce/editor.js";
import { getNew } from "@/api/artilce/editor.js";

const state = {
  artilceAllList: [],
  pageCount: 0,
  classifyList: [],
  htmlList:[]
};

const mutations = {
  update(state, payload) {
    for (const key in payload) {
      state[key] = payload[key];
    }
  },
};

const actions = {
  async getArtilceAll({ commit }, payload) {
    console.log("payload...", payload);
    const { page = 1, pageSize = 3, ...options } = payload;
    const result = await getArtilceAll(page, pageSize, options);
    console.log("result...", result);
    if (result.data) {
      commit("update", {
        pageCount: result.data[1],
        artilceAllList: result.data[0],
      });
    }
  },

  //分类管理数据
  async getClassify({ commit }, payload) {
    const result = await getClassify();
    console.log("分类管理....", result.data);
    commit("update", {
      classifyList: result.data,
    });
  },

  //添加分类管理数据
  async getKind({ commit }, payload) {
    let { label, value } = payload;
    console.log(label, value);
    const result = await getKind(payload);
    console.log(result);
  },

  //新建文章
  // async getHtml({ commit }, obj={}) {
  //   console.log(obj,'store.obj.....');
  //   const result = await getHtml(obj);
  //   console.log(result);
  // },

  async getNew({commit},payload){
    console.log(payload);
    const result= await getNew(payload);
    console.log(result);
  }
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
};
